import { AttriType } from "core/typeDefine/typeDefine"
import utils from "core/utils/utils"

export class AttriItemModel {
    type: AttriType
    name: number | string
    value: number
    lvl: number
    constructor(opts: any = {}) {
        this.type = opts.type || AttriType.Attri
        this.name = opts.name || 0
        this.value = opts.value || 0
        this.lvl = opts.lvl || 0
    }
}


export class EquipmentItemModel {
    tid: number
    lvl: number
    str: number
    quality: number
    mainAttris: AttriItemModel[]
    subAttris: AttriItemModel[]
    power: number
    gems: ItemModel[]
    suitID: number
    washIndex: number //洗练属性
    enchant: number //淬洗次数
    forceLvl: number //锻造等级
    packageAttributesId: number//套装词缀
    constructor(opts) {
        this.tid = opts.tid || 0
        this.lvl = opts.lvl || 0
        this.str = opts.str || 0
        this.quality = opts.quality || 0
        this.mainAttris = opts.mainAttris || []
        this.subAttris = opts.subAttris || []
        this.power = opts.power || 0
        this.gems = opts.gems || []
        this.suitID = opts.suitID || 0
        this.washIndex = utils.isNull(opts.washIndex) ? null : opts.washIndex
        this.enchant = opts.enchant || 0
        this.forceLvl = opts.forceLvl || 0
        this.packageAttributesId = opts.packageAttributesId || 0
    }
}

export class SkillItemModel {
    tid: number
    mp: number
    quality: number
    aSkillIDs: { skillID: number, lvl: number, lvl2: number }[]
    constructor(opts: any = {}) {
        this.tid = opts.tid || 0
        this.quality = opts.quality || 0
        this.mp = opts.mp || 0
        this.aSkillIDs = opts.aSkillIDs || []
    }
}

export class PetItemModel {
    tid: number
    lvl: number
    quality: number
    type: number
    elements: number[]
    attriQualitys1: number[]
    attriQualitys2: number[]
    constructor(opts) {
        opts = opts || {}
        this.tid = opts.tid || 0
        this.lvl = opts.lvl || 1
        this.quality = opts.quality || 0
        this.type = opts.type || 0
        this.elements = opts.elements || []
        this.elements = this.elements.slice(0)
        this.attriQualitys1 = opts.attriQualitys1 || [0, 0, 0, 0, 0, 0, 0, 0, 0]
        this.attriQualitys1 = this.attriQualitys1.slice(0)
        this.attriQualitys2 = opts.attriQualitys2 || [0, 0, 0, 0, 0, 0, 0, 0, 0]
        this.attriQualitys2 = this.attriQualitys2.slice(0)
    }
}

export class ItemModel {
    tid: number
    stack: number
    pos: number
    hp: number //磨损值
    new: boolean
    lock: boolean
    equipment?: EquipmentItemModel
    skill?: SkillItemModel
    pet?: PetItemModel
    constructor(opts: any = {}) {
        this.tid = opts.tid || 0
        this.new = opts.new || false
        this.stack = opts.stack || 1
        this.pos = opts.pos || 0
        this.hp = opts.hp || 0
        this.lock = opts.lock || false
        this.equipment = opts.equipment ? new EquipmentItemModel(opts.equipment) : null
        this.skill = opts.skill ? new SkillItemModel(opts.skill) : null
        this.pet = opts.pet ? new PetItemModel(opts.pet) : null
    }
}